package com.ushine.web.component.authority.config;

import com.ushine.web.base.model.base.DataFilterMetaDataBO;
import com.ushine.web.base.model.system.UserDO;

/**
 * @Author: yls
 * @Date 2022/2/9 14:36
 * @Description: 传参数
 * @Version 1.0
 **/
public class DataFilterThreadLocal {

    private DataFilterThreadLocal() {

    }

    private static final ThreadLocal<DataFilterMetaDataBO> THREAD_LOCAL_DATA_FILTER = new InheritableThreadLocal<>();

    private static final ThreadLocal<UserDO> THREAD_LOCAL_USER = new InheritableThreadLocal<>();

    /**
     * 功能描述:
     * 〈 清理相关数据 〉
     *
     * @return : void
     * @author : yls
     * @date : 2022/2/10 9:28
     */
    public static void clear() {
        THREAD_LOCAL_DATA_FILTER.remove();
        THREAD_LOCAL_USER.remove();
    }

    /**
     * 功能描述:
     * 〈 设置数据 〉
     *
     * @param metaData 传输数据
     * @return : void
     * @author : yls
     * @date : 2022/2/10 9:29
     */
    public static void setDataFilter(DataFilterMetaDataBO metaData) {
        THREAD_LOCAL_DATA_FILTER.set(metaData);
    }

    /**
     * 功能描述:
     * 〈 设置数据 〉
     *
     * @param user 多线程传输用户信息
     * @return : void
     * @author : yls
     * @date : 2022/2/10 9:29
     */
    public static void setUser(UserDO user) {
        THREAD_LOCAL_USER.set(user);
    }

    public static DataFilterMetaDataBO getDataFilter() {
        return THREAD_LOCAL_DATA_FILTER.get();
    }

    public static UserDO getUser() {
        return THREAD_LOCAL_USER.get();
    }
}